home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / fpc / compiler / catch.pas < prev    next >
Pascal/Delphi Source File  |  1998-09-24  |  3KB  |  106 lines

  1. {
  2.     $Id: catch.pas,v 1.1.1.1 1998/03/25 11:18:12 root Exp $
  3.     Copyright (c) 1997-98 by Michael Van Canneyt
  4.  
  5.     Unit to catch segmentation faults and Ctrl-C and exit gracefully
  6.     under linux and go32v2
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 2 of the License, or
  11.     (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.   *********************************************************************
  23. }
  24. Unit catch;
  25. interface
  26. uses
  27. {$ifdef linux}
  28.   linux,
  29. {$endif}
  30. {$ifdef go32v2}
  31.   dpmiexcp,
  32. {$endif}
  33.   verbose;
  34.  
  35. Var
  36. {$ifdef linux}
  37.   NewSignal,OldSigSegm,OldSigInt : PSignalHandler;
  38. {$else}
  39.   NewSignal,OldSigSegm,OldSigInt : SignalHandler;
  40. {$endif}
  41.  
  42.  
  43. Implementation
  44.  
  45. {$ifdef linux}
  46. Procedure CatchSignal(Sig : Integer);
  47. {$else}
  48. Function CatchSignal(Sig : longint):longint;
  49. {$endif}
  50. begin
  51.   case Sig of
  52.    SIGSEGV : begin
  53.              { Temporary message - until we get an error number... }
  54.                writeln ('Panic : Internal compiler error, exiting.');
  55.                internalerror(9999);
  56.              end;
  57.     SIGINT : begin
  58.                WriteLn('Ctrl-C Signaled!');
  59.                Stop;
  60.              end;
  61.   end;
  62. {$ifndef linux}
  63.   CatchSignal:=0;
  64. {$endif}
  65. end;
  66.  
  67.  
  68. begin
  69. {$ifdef linux}
  70.   NewSignal:=PSignalHandler(@CatchSignal);
  71.   OldSigSegm:=Signal (SIGSEGV,NewSignal);
  72.   OldSigInt:=Signal (SIGINT,NewSignal);
  73. {$else}
  74.   NewSignal:=SignalHandler(@CatchSignal);
  75.   Signal (SIGSEGV,NewSignal);
  76.   Signal (SIGINT,NewSignal);
  77. {$endif}
  78. end.
  79.  
  80. {
  81.   $Log: catch.pas,v $
  82.   Revision 1.1.1.1  1998/03/25 11:18:12  root
  83.   * Restored version
  84.  
  85.   Revision 1.5  1998/03/10 01:17:15  peter
  86.     * all files have the same header
  87.     * messages are fully implemented, EXTDEBUG uses Comment()
  88.     + AG... files for the Assembler generation
  89.  
  90.   Revision 1.4  1998/03/02 01:48:07  peter
  91.     * renamed target_DOS to target_GO32V1
  92.     + new verbose system, merged old errors and verbose units into one new
  93.       verbose.pas, so errors.pas is obsolete
  94.  
  95.   Revision 1.3  1998/02/13 10:34:37  daniel
  96.   * Made Motorola version compilable.
  97.   * Fixed optimizer
  98.  
  99.   Revision 1.2  1998/01/27 23:34:35  peter
  100.     + SIGINT capture with exit. It works for linux and go32v2 (last one
  101.       not 100% yet)
  102.  
  103.   Revision 1.1.1.1  1997/11/27 08:32:51  michael
  104.   FPC Compiler CVS start
  105. }
  106.